package com.yx.changdao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yx.changdao.common.entity.SysDict;
import com.yx.changdao.common.mapper.SysDictMapper;
import com.yx.changdao.service.SysDictService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: <br/>
 * 字典表
 * <p>
 * <br/>
 * @Auther: walter
 * @create 2020/04/03 13:33
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {

    @Override
    public List<SysDict> getDictById(Integer dictId) {
        return this.list(new QueryWrapper<SysDict>().lambda().eq(SysDict::getParentId,dictId)
        .orderByAsc(SysDict::getCreateTime));
    }

    @Override
    public List<String> getByParent(Integer dictId) {
        return baseMapper.selectList(new QueryWrapper<SysDict>()
                .select(SysDict.DATA_VALUE).eq(SysDict.PARENT_ID,dictId))
                .stream().map(SysDict::getDataValue).collect(Collectors.toList());
    }
}
